

package com.hazelcast.jet.impl.execution;

/**
 * A marker interface used for Jet cooperative {@link Thread}s. Some code known
 * to not being cooperative can check it and fail if it's running on such a
 * thread. It can check using {@link #checkNonCooperative()}.
 */
public interface CooperativeThread {

    /**
     * Throws an error if the current thread is a cooperative thread.
     */
    static void checkNonCooperative() {
        if (Thread.currentThread() instanceof CooperativeThread) {
            throw new RuntimeException("A non-cooperative task attempting to run on a cooperative thread");
        }
    }
}
